<?php
// Redirect Search Engines to Search Page
//	
// Adapted from: http://www.ilovejackdaniels.com/php/google-style-keyword-highlighting/
// Adapted from: http://us3.php.net/array
function lilina_userapi_redirect($args)
{
    extract($args);

  if ((isset($_SERVER['HTTP_REFERER'])) and ($_SERVER['HTTP_REFERER'] != '')) {
    $keywords = "";
    $url = urldecode($_SERVER['HTTP_REFERER']);
    // Google
    if (eregi("www\.google",$url)) {
       preg_match("'(\?|&)q=(.*?)(&|$)'si", " $url ", $keywords);
    }
    // AllTheWeb
    if (eregi("www\.alltheweb",$url)) {
       preg_match("'(\?|&)q=(.*?)(&|$)'si", " $url ", $keywords);
    }
    // MSN
    if (eregi("search\.msn",$url)) {
       preg_match("'(\?|&)q=(.*?)(&|$)'si", " $url ", $keywords);
    }
    // Yahoo
    if ((eregi("yahoo\.com",$url)) or (eregi("search\.yahoo",$url))) {
       preg_match("'(\?|&)p=(.*?)(&|$)'si", " $url ", $keywords);
    }
    // Looksmart
    if (eregi("looksmart\.com",$url)) {
       preg_match("'(\?|&)qt=(.*?)(&|$)'si", " $url ", $keywords);
    }
    if ((isset($keywords[2])) and ($keywords[2] != ' ')) {
       $keywords = preg_replace('/"|\'/', '', $keywords[2]); // Remove quotes
       $keyword_array = preg_split("/[\s,\+\.]+/",$keywords); // Create keyword array
        $keyword_array = array_unique($keyword_array);
        $redirect = implode(' ', $keyword_array);
        xarResponseRedirect(xarModURL('lilina', 'user', 'search', array('q' => $redirect)));
    }
    return;
   }
}
?>